package cn.alusiaor.springbootsecurity.controller;



import cn.alusiaor.springbootsecurity.annotation.WebLog;
import cn.alusiaor.springbootsecurity.entity.User;
import cn.alusiaor.springbootsecurity.exception.MyException;
import cn.alusiaor.springbootsecurity.service.ITestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * @author zhuzhiping
 * @date 2019/12/9
 * @description 功能描述
 */


@RestController
@Slf4j
@Validated
public class HelloWorldController {
    @Autowired
    private ITestService testService;

    @WebLog(description = "测试异常")
    @GetMapping("/exception")
    public String testController() {
        throw new MyException("产生异常啦");
    }


    @WebLog(description = "参数映射异常")
    @PostMapping("test1")
    public String test1(
            @NotBlank(message = "姓名不能为空") String name,
            @NotBlank(message = "邮箱不能为空") String email) {
        return "success";
    }

    @WebLog(description = "参数绑定异常")
    @PostMapping("test3")
    public String test3(@Validated User user) {
        System.out.println(user.toString());
        return "success";
    }


}
